#include "App.h"

#include <future>

#include "Display.h"

namespace core{
    typedef core::form::AbstractForm IForm;

    namespace app{
        namespace Msg = util::message; 

        App::App() : formTree(){
        }

        HRESULT App::Initialize(){
            HRESULT hr = S_OK;

            hr = display::INSTANCE.Initialize();
            if(!SUCCEEDED(hr))
                return hr;
            formTree.root = new FormNode();

            core::form::FormFactory formFactory(this, core::form::main_form, HINST_THISCOMPONENT);
            formFactory.SetWndSize(400,400);
            formFactory.SetStyle(WS_DLGFRAME);
            hr = formFactory.CreateForm(&formTree.root->data);
            if(!SUCCEEDED(hr))
                return hr;
            hr = formTree.root->data->ShowForm();
            return hr;
        }

        void App::RunMessageLoop()
        {
            MSG msg;

            while (GetMessage(&msg, NULL, 0, 0))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
                // BOOL is = formTree.root->data->UpdateForm();
            }
        }

        bool App::Receive(Msg::MessageType msg, void * param){
            return false;
        }


        void App::Exit(){
            form::FormFactory::UnregisterWndClass();
            display::INSTANCE.~ResourceFactory();
        }

        App::~App(){

        }
    }
}